package com.moon.service.impl;

import com.moon.annotations.DataSource;
import com.moon.mapper.DeptMapper;
import com.moon.pojo.Dept;
import com.moon.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Override
    @DataSource("db02")
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        deptMapper.addDept(dept);
    }

    @Override
    @DataSource("db02")
    public Dept getDept(Integer id, String deptName) {
        return deptMapper.getDept(id, deptName);
    }

    @Override
    @DataSource("db02")
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }
}
